package com.ly.blog2Word.controller;

import com.alibaba.fastjson.JSONObject;
import com.ly.blog2Common.core.http.ResponseMessage;
import com.ly.blog2Common.core.page.PageRequest;
import com.ly.blog2Word.dao.model.WordArticle;
import com.ly.blog2Word.service.WordArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: lyMaster
 * @time: 2020/7/17 19:16
 */
@RequestMapping("/article")
@RestController
public class WordArticleController {


    @Autowired
    private WordArticleService wordArticleService;

    @PostMapping(value="/save")
    public JSONObject save(@RequestBody WordArticle record) {
        return ResponseMessage.ok(wordArticleService.save(record));
    }

    @PostMapping(value="/delete")
    public JSONObject delete(@RequestBody List<WordArticle> records) {
        return ResponseMessage.ok(wordArticleService.delete(records));
    }

    @PostMapping(value="/findPage")
    public JSONObject findPage(@RequestBody PageRequest pageRequest) {
        return ResponseMessage.ok(wordArticleService.findPage(pageRequest));
    }

    @PostMapping(value="/findPageShow")
    public JSONObject findPageShow(@RequestBody PageRequest pageRequest) {
        return ResponseMessage.ok(wordArticleService.findPageShow(pageRequest));
    }

    /**
     * 查询文章详情，添加浏览次数
     * @param idObj
     * @return
     */
    @PostMapping(value="/findById")
    public JSONObject findById(@RequestBody JSONObject idObj) {
        return ResponseMessage.ok(wordArticleService.findById(idObj.getLong("id")));
    }
    @PostMapping(value="/findAddLabelById")
    public JSONObject findAddLabelById(@RequestBody JSONObject idObj) {
        return ResponseMessage.ok(wordArticleService.findAddLabelById(idObj.getLong("id")));
    }

    
}
